<?php

/**
* @Author:  	Daniel Dinh
* @Email:   	webdevelopmentvn@gmail.com
* @Link: 		http://joomsoft.net
* @Version: 	1.0
* @copyright:	Joomsoft.net
* @license:		GNU Lesser GPL
*/

// No direct access
defined('_JEXEC') or die;

jimport('joomla.application.component.view');
JLoader::register('FarmacityHelper', JPATH_COMPONENT.'/helpers/farmacity.php');

class FarmacityViewPeriod extends JView
{
	protected $form;
	protected $item;
	protected $state;

	/**
	 * Display the view
	 */
	public function display($tpl = null)
	{
		// Initialiase variables.
		$this->form		= $this->get('Form');
		$this->item		= $this->get('Item');
		$this->state	= $this->get('State');
		$this->user	= JFactory::getUser();


		// Check for errors.
		if (count($errors = $this->get('Errors'))) {
			JError::raiseError(500, implode("\n", $errors));
			return false;
		}
		$user = & JFactory::getUser();
		$this->form->setValue('id_user',$user->get('id'));
		
		
		if($_SESSION['jform'])
		{
			$this->form->setValue('title','',$_SESSION['jform']['title']);
			$this->from_date = $_SESSION['jform']['from'];
			$this->to_date = $_SESSION['jform']['to'];
		}
		else
		{
			$this->form->setValue('title','',$this->item->title);
			$this->from_date = $this->item->dal;
			$this->to_date = $this->item->al;
		
		}
		
		

		$doc = & JFactory::getDocument();
		$doc->addStyleSheet(JURI::root().'components/com_farmacity/assets/css/farmacity.css');
		$doc->addScript(JURI::root().'components/com_farmacity/assets/js/script.js');

		//$this->addToolbar();
		unset($_SESSION['jform']);
		parent::display($tpl);
	}

	/**
	 * Add the page title and toolbar.
	 *
	 * @since	1.6
	 */
	public function getMonths($name, $sel)
	{
		$months =array(
			array('value'=>'01','text'=>JText::_("COM_FARMACITY_MONTH_01")),
			array('value'=>'02','text'=>JText::_("COM_FARMACITY_MONTH_02")),
			array('value'=>'03','text'=>JText::_("COM_FARMACITY_MONTH_03")),
			array('value'=>'04','text'=>JText::_("COM_FARMACITY_MONTH_04")),
			array('value'=>'05','text'=>JText::_("COM_FARMACITY_MONTH_05")),
			array('value'=>'06','text'=>JText::_("COM_FARMACITY_MONTH_06")),
			array('value'=>'07','text'=>JText::_("COM_FARMACITY_MONTH_07")),
			array('value'=>'08','text'=>JText::_("COM_FARMACITY_MONTH_08")),
			array('value'=>'09','text'=>JText::_("COM_FARMACITY_MONTH_09")),
			array('value'=>'10','text'=>JText::_("COM_FARMACITY_MONTH_10")),
			array('value'=>'11','text'=>JText::_("COM_FARMACITY_MONTH_11")),
			array('value'=>'12','text'=>JText::_("COM_FARMACITY_MONTH_12"))
		);
		
		return JHTML::_("select.genericlist",$months,$name,"style='width:150px;'","value","text",$sel);
	}
	public function getDays($name, $sel)
	{
		$days = array();
		for($i=1;$i<=31;$i++)
			if($i<10)
				$days[] = array('value'=>'0'.$i,'text'=>'0'.$i);
			else
				$days[] = array('value'=>$i,'text'=>$i);
		return JHTML::_("select.genericlist",$days,$name,"style='width:50px;'","value","text",$sel);
	}
	
}
